/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import voidlib.VoidController;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import models.Credit;
import models.mappers.*;
import models.RequestStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import voidlib.*;

/**
 *
 * @author nevidimov
 */
public class HelloController extends VoidController {
    
    public HelloController() {
    }
    
    public void indexAction()
    {
        VoidMapper mapper = new Credit().getMapper();
        Credit cr = (Credit)mapper.fetch(1);
        
        this.view.put("id", cr._status.toString());
        this.initModelAndView();;
    }
    
    public void addCreditAction()
    {
        Credit cr = new Credit();
        cr._amount = 1;
        cr._bankId = 2;
        cr._businessmanId = 3;
        cr._status = RequestStatus.Pending;
        cr.save();
        this.view.put("actionName", "index");
        this.initModelAndView();;
    }
    
    public void deleteCreditsAction() 
    {
        new Credit().getMapper().delete("id = ?", 2);
    }
    
    public void listCreditsAction()
    {
        List<VoidModel> res = new Credit().getMapper().fetchAll("status = ?", RequestStatus.Pending);
        String tmp = "";
        for (VoidModel m : res) {
            Credit cr = (Credit)m;
            tmp += cr._id + " ";
        }
        this.view.put("id", tmp);
        
        this.view.put("actionName", "index");
        this.initModelAndView();;
    }
}
